package crmsystem.com.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import crmsystem.com.entity.EmployeeEntity;
import crmsystem.com.service.EmployeeService;
import crmsystem.com.utils.PageUtils;
import crmsystem.com.utils.R;

import javax.validation.Valid;


/**
 * 
 *
 * @author zhugaowei
 * @email 1912431877@qq.com
 * @date 2021-01-07 12:48:11
 */
@RestController
@RequestMapping(value = "/employee")
//@Api(value = "EmployeeController")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    /**
     * 列表
     */
    @RequestMapping(value = "/list" , method = RequestMethod.GET)
    //@RequiresPermissions("com:employee:list")
//    @ApiOperation(notes = "查询所有", value = "list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = employeeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping(value = "/info/{eId}" , method = RequestMethod.GET)
//    @ApiOperation(notes = "根据id查询", value = "info")
    //@RequiresPermissions("com:employee:info")
    public R info(@PathVariable("eId") Integer eId){
		EmployeeEntity employee = employeeService.getById(eId);

        return R.ok().put("employee", employee);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save" , method = RequestMethod.POST)
    //@RequiresPermissions("com:employee:save")
//    @ApiOperation(notes = "保存", value = "save")
    public R save(@Valid @RequestBody EmployeeEntity employee){
		employeeService.save(employee);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update" , method = RequestMethod.POST)
//    @ApiOperation(notes = "修改", value = "update")
    //@RequiresPermissions("com:employee:update")
    public R update(@Valid @RequestBody EmployeeEntity employee){
		employeeService.updateById(employee);

        return R.ok();
    }

    /**
     * 批量删除
     */
    @RequestMapping(value = "/delete" , method = RequestMethod.POST)
//    @ApiOperation(notes = "批量删除", value = "delete")
    //@RequiresPermissions("com:employee:delete")
    public R delete(@RequestBody Integer[] eIds){
		employeeService.removeByIds(Arrays.asList(eIds));

        return R.ok();
    }

    /**
     *根据id删除
     */
    @RequestMapping(value = "/delete/{eId}" , method = RequestMethod.POST)
//    @ApiOperation(notes = "根据id删除", value = "deleteById")
    //@RequiresPermissions("com:business:delete")
    public R deleteById(@PathVariable("eId") Integer eId){
        employeeService.removeById(eId);
        return R.ok();
    }

    /**
     * 多字段模糊查询
     */
    @RequestMapping("/infoByIndex/{index}")
    //@RequiresPermissions("com:contactperson:info")
    public R infoByIndex(@PathVariable("index") String index){
        List<EmployeeEntity> entities = employeeService.getByIndex(index);
        return R.ok().put("entities", entities);
    }
}
